<?php
ob_implicit_flush(true);
$bufLength=256;

$method=$_POST['method'];
$target=base64_decode($_POST['target']);
$url=base64_decode($_POST['url']);
$protocol=base64_decode($_POST['protocol']);
$header=explode("|",$_POST['header']);
$headerSize=count($header)-1;
$decodedHeader=array();
for($i=0;$i<$headerSize;$i++){
    $decodedHeader[$i]=base64_decode($header[$i]);
}
$data=base64_decode($_POST['data']);
$haveEntity=($method==="POST");
$port=base64_decode($_POST['port']);

$socket = fsockopen( $target, $port,$errno,$errstr,10);
$CRLF="\r\n";
if( ! $socket ) {
	echo $protocol." 500 Connection failed.".$CRLF.$CRLF. "Connection failed to " . $target . ":" . $port .$CRLF;
}else{
stream_set_timeout($socket , 2);
fputs($socket , $method . " " . $url . " " . $protocol . $CRLF);

for($i=0;$i<$headerSize;$i++){
    fputs($socket , $decodedHeader[$i] . $CRLF);
}

fputs($socket , $CRLF);
fputs($socket , $data);
fputs($socket , $CRLF);

while(!feof($socket)){

$buf=fread($socket,$bufLength);

echo $buf;
}
fclose($socket);
}
?>		